<!-- 
    @author Wójcik Karol <wojcikk@student.agh.edu.pl>
    @licence http://www.gnu.org/copyleft/gpl.html GNU/GPL
-->

<div id="colOne">
&nbsp;
</div>
<div id="colTwo">
<%= start_form_tag :action => 'index' %>
<table border='0' cellpadding='5'>
<tr><td><%= check_box_tag "columns[]", "year", @columns.include?("year") %> Rok </td></tr>
<tr><td><%= check_box_tag "columns[]", "subject", @columns.include?("subject") %> Przedmiot </td></tr>
<tr><td><%= check_box_tag "columns[]", "class_type", @columns.include?("class_type") %> Typ zajec </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgrzaj", @columns.include?("lgrzaj") %> LGrZaj </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgrroz", @columns.include?("lgrroz") %> LGrRoz </td></tr>
<tr><td><%= check_box_tag "columns[]", "lgodzin", @columns.include?("lgodzin") %> LGodzin </td></tr>
<tr><td><%= check_box_tag "columns[]", "sums", @columns.include?("sums") %> Podsumowanie </td></tr>
<tr><td><%= submit_tag 'Wybierz' %> </td></tr>
</table>
<%= end_form_tag %>

<% teachers_report =  '\documentclass[a4paper,10pt]{report} \usepackage[polish]{babel} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \begin{document}' 
teachers_report << '\begin{tabular}{|c c|p{1 in}|p {1 in }|c|c|c|c|} '
%>
<table width='80%' border='0' CELLPADDING='5'><tr>
<%
login_old = ""
semestr_old = ""
major_old = ""

for user in @users
    login = "#{user.login}"
    semestr = "#{user.semestr}"
    major = "#{user.major}"


	if login_old != login 
		semestr_old = "" 
		major_old = ""
%>

<td colspan='8'><table align='right' border='0'><tr>
<%
		for sum in @sums
				sums_login = "#{sum.login}" 
				if sums_login == login_old
					if @columns.include?("sums")
			%>
				<td><%=h "#{sum.study_type}" %><br/><%=h "#{sum.all}" %></td>
			<% 		end
				end 
			end  
			
  
		%>
			</tr>
			</table>
		</tr>
		<tr><td colspan='8'>&nbsp;</td></tr>
		<tr><td colspan='8'><h3><%=h "#{user.mark} #{user.name} #{user.surname}" %></h3></td></tr>
		<% teachers_report << '\multicolumn{7}{l}{ \begin{Large}'
			teachers_report << "#{user.mark} #{user.name} #{user.surname}"
			teachers_report << '\end{Large} }  \\\\  ' %>

			

		
	<% end 
	if semestr != semestr_old 
	major_old = "" %>
		<tr><td colspan='8'><h4>&nbsp;&nbsp;<%=h "#{user.semestr} "%></h4></td></tr>
			<% teachers_report << '\multicolumn{7}{l}{ '
				teachers_report << "#{user.semestr}"
				teachers_report << '} \\\\  ' %>
	<% end 
	if major_old != major %>
		<tr><td colspan='8'><h4>&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{user.major} "%></h4></td></tr>
		<% teachers_report << '\multicolumn{7}{l}{ ' 
			teachers_report << "#{user.major}"
			teachers_report << '} \\\\ \hline ' 
			teachers_report <<' & Rok & Przedmiot & Typ Zajec & LGrZaj & LGrRoz  & LGodzin \\\\ \hline ' 
			%>
		<tr>
			<td WIDTH='30px' >&nbsp;</td>
			<% if @columns.include?("year")%>
			<td WIDTH='20px' ><b>Rok</b></td>
			<% end %> 
			<% if @columns.include?("subject")%>
			<td WIDTH='200px'><b>Przedmiot</b></td>
			<% end %>
			<% if @columns.include?("class_type")%>
			<td WIDTH='70px' ><b>Typ Zajec</b></td>
			<% end %> 
			<% if @columns.include?("lgrzaj")%>
			<td WIDTH='20px' ><b>LGrZaj</b></td>
			<% end %> 
			<% if @columns.include?("lgrroz")%>
			<td WIDTH='20px' ><b>LGrRoz</b></td>
			<% end %> 
			<% if @columns.include?("lgodzin")%>
			<td WIDTH='20px' ><b>LGodzin</b></td>
			<% end %> 
		</tr>
	<% 	end 
		teachers_report <<' & '
		teachers_report << "#{user.year}"
		teachers_report << ' & ' 
		teachers_report << "#{user.subject}" 
		teachers_report << ' & ' 
		teachers_report << "#{user.class_type}"
		teachers_report<< ' & ' 
		teachers_report << "#{user.lgrzaj}" 
		teachers_report << ' & ' 
		teachers_report << "#{user.lgrroz}"
		teachers_report << ' & ' 
		teachers_report << "#{user.lgodzin}"
		teachers_report << '\\\\ \hline ' 
		%>
		<tr>
			
			
			<td WIDTH='30px' >&nbsp;</td>
			<% if @columns.include?("year")%>			
			<td WIDTH='20px' ><%=h "#{user.year}" %></td>
			<% end %> 
			<% if @columns.include?("subject")%>
			<td WIDTH='200px'>  <%= link_to "#{user.subject}", :action => 'detail_subject', :id => user.sid%></td>
			<% end %> 
			<% if @columns.include?("class_type")%>
			<td WIDTH='70px' ><%=h "#{user.class_type}" %></td>
			<% end %> 
			<% if @columns.include?("lgrzaj")%>
			<td WIDTH='20px' ><%=h "#{user.lgrzaj}" %></td>
			<% end %> 
			<% if @columns.include?("lgrroz")%>
			<td WIDTH='20px' ><%=h "#{user.lgrroz}" %></td>
			<% end %> 
			<% if @columns.include?("lgodzin")%>
			<td WIDTH='20px' ><%=h "#{user.lgodzin}" %></td>
			<% end %> 
			
		</tr>
		

<% 	
	login_old = "#{user.login}"    
	semestr_old = "#{user.semestr}"
	major_old = "#{user.major}"

	
end
%>
<tr>
	<td colspan='8'>
		<table align='right' border='0'><tr>
<%
for sum in @sums
				sums_login = "#{sum.login}" 
				if sums_login == login_old
					if @columns.include?("sums")
			%>
				<td><%=h "#{sum.study_type}" %><br/><%=h "#{sum.all}" %></td>
			<% 		end
				end 
			end  

%>
</tr></table>
</table>
<% teachers_report << '\end{tabular} \end{document}'%>
<%=h   "#{teachers_report}" %>
</div>